import load
import os

class item:
    def __init__(self,no,name,score,subject):
        self.no=no
        self.name=name
        self.score=score
        self.subject=subject

    def output(self):
        return str(self.no)+','+self.name+','+str(self.score)+','+self.subject+'\n'

allTable={}

def makeTable(table,num):
    for i in range(1,num):
        Class=load.getCell(i, load.Class, table)
        subNo=load.getCell(i,load.subNo,table)
        key=Class+'_'+str(subNo)
        if not key in allTable.keys():
            allTable[key]=[]
        no=load.getCell(i,load.no,table)
        name=load.getCell(i,load.name,table)
        score=load.getScore(i,table)
        subject = load.getCell(i, load.subject, table)
        allTable[key].append(item(no,name,score,subject))

# 想统计成绩.xlsx的哪个表对哪个调用makeTable，现在默认全调用
makeTable(load.x1,load.len1)
makeTable(load.x2,load.len2)
makeTable(load.x3,load.len3)

for k,v in allTable.items():
    content='学号,姓名,分数,课程\n'
    for i in v:
        c=i.output()
        if c!='':
            content+=i.output()
    print(k)
    print(content)
    _,sub=k.split('_')
    path='class/'+sub+'/'
    if not os.path.exists(path):
        os.mkdir(path)
    load.writeFile(path+k+'.csv',content)